package javafx.fxml;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 可执行方法
 *
 */
public interface InvokeAbleMethod {

    void invoke(Object... args) throws InvocationTargetException, IllegalAccessException;

    static InvokeAbleMethod getInstance(Object controller, Method method){
        return new DefaultInvokeAbleMethodImpl(controller, method);
    }

    /**
     * 默认的可执行方法实现
     *
     * @param object 执行对象
     * @param method 执行方法
     */
    record DefaultInvokeAbleMethodImpl(Object object, Method method) implements InvokeAbleMethod {

        @Override
        public void invoke(Object... args) throws InvocationTargetException, IllegalAccessException {
            method.invoke(object, args);
        }
    }
}
